Page({
  data: {
    activeSection: 'overview',
    sections: ['overview', 'updates', 'features', 'tech', 'about'],
    scrollIntoView: '',
    sidebarVisible: false
  },

  onLoad() {
    // 页面加载时的初始化
  },

  /**
   * 切换侧边栏显示/隐藏
   */
  toggleSidebar() {
    this.setData({
      sidebarVisible: !this.data.sidebarVisible
    });
  },

  /**
   * 滚动到指定区域
   */
  scrollToSection(e) {
    const section = e.currentTarget.dataset.section;
    this.setData({ 
      activeSection: section,
      scrollIntoView: section
    });
    
    // 在移动端，点击菜单后自动隐藏侧边栏
    if (this.data.sidebarVisible) {
      setTimeout(() => {
        this.setData({
          sidebarVisible: false
        });
      }, 300);
    }
  },

  /**
   * 监听滚动事件，更新当前激活的菜单项
   */
  onScroll(e) {
    const scrollTop = e.detail.scrollTop;
    
    // 获取所有区域的位置信息
    const query = wx.createSelectorQuery();
    this.data.sections.forEach(section => {
      query.select(`#${section}`).boundingClientRect();
    });
    query.exec((res) => {
      if (res && res.length > 0) {
        let currentSection = 'overview';
        
        // 找到当前滚动位置对应的区域
        for (let i = 0; i < res.length; i++) {
          const rect = res[i];
          if (rect && scrollTop >= rect.top - 100 && scrollTop < rect.top + rect.height - 100) {
            currentSection = this.data.sections[i];
            break;
          }
        }
        
        // 更新激活的菜单项
        if (this.data.activeSection !== currentSection) {
          this.setData({ activeSection: currentSection });
        }
      }
    });
  },

  /**
   * 分享功能
   */
  onShareAppMessage() {
    return {
      title: '品轩小程序 - 项目说明',
      path: '/pages/project-desc/project-desc',
      imageUrl: '/assets/share-image.png'
    };
  },

  /**
   * 分享到朋友圈
   */
  onShareTimeline() {
    return {
      title: '品轩小程序 - 项目说明',
      imageUrl: '/assets/share-image.png'
    };
  }
}); 